package com.jfinal.bbsapp.info;
import java.util.List;
import org.apache.log4j.Logger;
import com.jfinal.bbsapp.common.kit.MyAnnotation;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Page;
import com.jfinal.plugin.activerecord.Record;

@MyAnnotation(memo="信息资讯业务类")
public class FpService {
	private final Logger logger = Logger.getLogger(FpService.class);
	
	@MyAnnotation(memo="最新信息列表")
	public Ret list() {
		try {
			StringBuilder sql = new StringBuilder();
			sql.append("select cast(infoid as char) infoid,source,title,titleimgurl,content,sortno,from_unixtime(ctime/1000) ctime");
			sql.append(" from a_info where flag='1'");
			sql.append(" order by sortno desc limit 6");
			List<Record> list = Db.find(sql.toString());
			return Ret.ok("data", list).set("code", 20000);
		} catch (Exception e) {
			logger.error("------Exception------", e);
			return Ret.fail("系统异常").set("code", 50000);
		}
	}
	
	@MyAnnotation(memo="更多信息分页列表")
	public Ret plist(String token,int pagecurrent, int pagesize) {
		try {
			String querySql = "select cast(infoid as char) infoid,source,title,titleimgurl,content,sortno,from_unixtime(ctime/1000) ctime";	
			StringBuilder sql = new StringBuilder();
			sql.append(" from a_info where flag='1'");
			sql.append(" order by sortno desc");
			Page<Record> page = Db.paginate(pagecurrent, pagesize, querySql, sql.toString());
			return Ret.ok("data", page).set("code", 20000);
		} catch (Exception e) {
			logger.error("------Exception------", e);
			return Ret.fail("系统异常").set("code", 50000);
		}
	}
}